package Classes
{
	import flash.display.Sprite;
	import flash.events.TimerEvent;
	import flash.text.TextField;
	import flash.utils.Timer;

	public class PerfTracker
	{
		private var m_display:Sprite = new Sprite();
		private var m_textField:TextField = new TextField();
		private var m_updateTimer:Timer = new Timer(500);
		private var m_lastDelta:int;
		
		public function PerfTracker()
		{
			m_display.addChild(m_textField);
			m_updateTimer.addEventListener(TimerEvent.TIMER, onTimerTick);
		}
		
		public function getDisplay():Sprite{
			return m_display;
		}
		
		private function onTimerTick(te:TimerEvent):void{
			m_updateTimer.stop();
			var fps:int = Math.floor(1000/m_lastDelta);
			m_textField.text = 'FPS: ' + fps;			
		}
		
		public function update(delta:int):void{
			m_lastDelta = delta;
			if(!m_updateTimer.running){
				m_updateTimer.start();
			}
		}
	}
}